<template >
	<view class="shop">
		<navbar class="shop-navbar" mode="main" @drawer="drawer"></navbar>
		<scroll-view v-if="canshow" scroll-y="true" class="shop-content" >
			<shop-swiper :goodsList="goodsList"></shop-swiper>
			<shop-buttoms class="shop-bottoms"></shop-buttoms>
			<shop-cards :goodsList="goodsList" class="shop-cards"></shop-cards>
		</scroll-view>
		<uni-drawer ref="showDrawer">
			<drawer @exit="exit"></drawer>
		</uni-drawer>
		<uni-popup type="bottom" ref="pop_exit">
			<view class="box">
				<view class="text">确定要退出登录吗？</view>
				<view class="confirm" @click="exitC">
					确定
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				goodsList:[],
				canshow:false
			};
		},
		methods:{
			exitC(){
				uni.clearStorage()
				this.$refs.pop_exit.close()
				uni.showToast({
					title:"退出登录成功~即将返回登录页"
				})
				setTimeout(function(){
					uni.hideToast()
					uni.redirectTo({
						url:"../../login/login"
					})
				},1000)
			},
			exit(){
				this.$refs.showDrawer.close()
				this.$refs.pop_exit.open()
			},
			drawer(){
				this.$refs.showDrawer.open()
			},
			getAllGoods(){
				this.$request("goods/getAll",{},(res)=>{ //发送请求查询全部商品
					if(res.data.code === 200){
						this.goodsList = this.$fixGoods(res.data.data)	//修复goods的json文件
						this.canshow = true
						uni.hideLoading()
					}
				})
			}
		},
		onLoad() {
			uni.showLoading({})
			this.getAllGoods()
		},
		onShow() {
			uni.showLoading({})
			this.canshow = false
			setTimeout(()=>{
				this.getAllGoods()
			}, 1)
		}
	}
</script>

<style lang="scss">
	page,body,html,template{
		width: 100%;
		height: 100%;
		box-sizing: border-box;
	}
	.shop{
		width: 100%;
		height: 100%;
		display: flex;
		position: relative;
		overflow: hidden;
		flex-direction: column;
		.box{
			width: 100%;
			height: 400rpx;
			background-color: #Fff;
			border-radius: 40rpx;
			//border: 4rpx red solid ;
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			position: relative;
			.text{
				font-size: 40rpx;
				position: relative;top: -40rpx;
			}
			.confirm{
				font-size: 32rpx;
				position: absolute;
				bottom: 120rpx;
				right: 80rpx;
				color: $my-main-color;
			}
		}
		.shop-content{
			//border: 6rpx green solid;
			height: 100%;
			width: 100%;
			display: flex;
			flex-direction: column;
			
			.shop-bottoms{
				margin-left: 2rpx;
				box-shadow: 0rpx 6rpx 10rpx #ccc;
			}
			
			.shop-cards{
				margin-top: 10rpx;
			}
		}
	}
</style>
